﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using GsifWeb4.Models;
using GsifWeb4.ViewModels;

namespace GsifWeb4.Controllers
{
    public class PhoneListController : Controller
    {
        //
        // GET: /PhoneList/

        gsifdbEntities gsifDB = new gsifdbEntities();

        public ActionResult Index()
        {
            if (User.Identity == null || string.IsNullOrEmpty(User.Identity.Name))
            {
                return View("UserNotLoggedIn");
            }

            laget_gsif loggedInPlayer = Common.GetPlayerFromUserName(gsifDB, User.Identity.Name);
            List<StatusValue> selectedTeams = new List<StatusValue>();
            selectedTeams.Add(Statuses.GetStatusFromDbValue(Team.AllTeams, loggedInPlayer.Lag));

            PhoneListViewModel phoneListViewModel = new PhoneListViewModel(selectedTeams, gsifDB);

            return View(phoneListViewModel);
        }

        [HttpPost]
        public ActionResult Index(FormCollection collection)
        {
            List<StatusValue> selectedTeams = new List<StatusValue>();
            foreach (var team in Team.AllTeams)
            {
                if (Common.IsCheckboxTrue(collection[team.Text]))
                    selectedTeams.Add(team);
            }

            PhoneListViewModel phoneListViewModel = new PhoneListViewModel(selectedTeams, gsifDB);
            return View(phoneListViewModel);
        }

       

    }
}
